#include <interface\button.h>
#include <interface\frame.h>
#include <interface\gl.h>

button::button():   abstractButton()
{
        margin.left = 2;
        margin.top = 2;
        margin.bottom = 2;
        margin.right = 2;
        ELname = "<button>";
}
button::button(window* win):    abstractButton(win)
{
        margin.left = 2;
        margin.top = 2;
        margin.bottom = 2;
        margin.right = 2;
        ELname = "<button>";
}

void button::setMargin(int left,int bottom,int right,int top){
    margin.left = left;
    margin.right = right;
    margin.top = top;
    margin.bottom = bottom;
}

void button::setLabel(string lbl){
    label.setCaption(lbl);
}
string button::getLabel(){
    return label.getCaption();
}

void button::setFont(font* ft){
    label.setFont(ft);
}

color* button::bkgColFromSS(elTy type){
    if( !styleS ) return NULL;
    color* out;
    if( status && (out = styleS->getColor(type|STATUS(bkg_st_on)))) return out;
    return winElmt::bkgColFromSS(type);
}
color* button::txtColFromSS(elTy type){
    if( !styleS ) return NULL;
    color* out;
    if( status && (out = styleS->getColor(type|STATUS(txt_st_on)))) return out;
    return winElmt::txtColFromSS(type);
}

void button::display(){
    if( !styleS ) return;
    abstractButton::display();
    int pOffX = 0;
    int pOffY = 0;
    getOffset( &pOffX, &pOffY );
    glColor(bkgColFromSS(elm_button));
    glDrawRect(enc,pOffX,pOffY);
    glColor(txtColFromSS(elm_button));
    label.display(enc.left+pOffX-1+margin.left,enc.bottom+pOffY+1+margin.bottom);
}
